package sf.model;

import java.util.HashMap;

public class Context {
	/** objekat koji je instancirao ovu formu (menu, zoom, next...) */
	private Object caller;
	/** parametri konteksta (mode, selectedRow, table...) */
	private HashMap<String, Object> params = new HashMap<String, Object>();

	@Deprecated
	public Context(int mode, String table, int selectedRow) {
		setMode(mode);
		setTable(table);
		setSelectedRow(selectedRow);
	}

	public Context(Object caller, int mode, String table) {
		setCaller(caller);
		setMode(mode);
		setTable(table);
	}

	public Context(Object caller) {
		setCaller(caller);
	}

	/**
	 * Kreira novu instancu standardne forme.
	 * 
	 * @param caller
	 *            Objekat koji je zatrazio kreiranje forme. Moze biti zoomfield,
	 *            stavka iz menia, next akcija ili bilo sta drugo (pa i null).
	 * @param params
	 *            HashMap parametara za kreiranje standardne forme. Standardni
	 *            parametri su mode, table i selectedRow. Ostali parametri su
	 *            opcioni i zavise od caller-a.
	 */
	public Context(Object caller, HashMap<String, Object> params) {
		setCaller(caller);
		setParams(params);
	}

	public int getMode() {
		return ((Integer) params.get("mode")).intValue();
	}

	public void setMode(int mode) {
		params.put("mode", new Integer(mode));
	}

	public String getTable() {
		return (String) params.get("table");
	}

	public void setTable(String table) {
		params.put("table", table);
	}

	public int getSelectedRow() {
		return ((Integer) params.get("selectedRow")).intValue();
	}

	public void setSelectedRow(int selectedRow) {
		params.put("selectedRow", new Integer(selectedRow));
	}

	public Object getCaller() {
		return caller;
	}

	public void setCaller(Object caller) {
		this.caller = caller;
	}

	public HashMap<String, Object> getParams() {
		return params;
	}

	public void setParams(HashMap<String, Object> params) {
		this.params = params;
	}

	public void setParam(String key, Object value) {
		params.put(key, value);
	}

	public Object getParam(String key) {
		return params.get(key);
	}

}